package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.entity.User;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author 星河一叶Ck
 * @date 2024/10/6
 */

@Mapper
public interface AdminOrdersMapper {

    /**
     * 条件订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> queryOrderPage(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单号查询订单详情
     * @param id
     * @return
     */
    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetail> getOrderDetailByOrderId(Long id);

    /**
     * 统计待接单数量
     * @param toBeConfirmed
     * @return
     */
    @Select("select count(*) from orders where status = #{toBeConfirmed}")
    Integer ToBeConfirmedCount(Integer toBeConfirmed);

    /**
     * 统计待派送数量
     * @param confirmed
     * @return
     */
    @Select("select count(*) from orders where status = #{confirmed}")
    Integer ConfirmedCount(Integer confirmed);

    /**
     * 统计派送中的数量
     * @param deliveryInProgress
     * @return
     */
    @Select("select count(*) from orders where status = #{deliveryInProgress}")
    Integer DeliveryCount(Integer deliveryInProgress);

    /**
     * 查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);

    /**
     * 更新操作
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据条件统计订单数
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 统计营业额
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 统计新用户数量
     * @param map
     * @return
     */
    @Select("select count(id) from user where create_time >= #{begin} and create_time <= #{end}")
    Integer newUserCount(Map map);
}
